home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Lib / DTS.Lib.headers / TextEditControl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-12  |  38.1 KB  |  937 lines  |  [TEXT/KAHL]

  1. #ifndef __TEXTEDITCONTROL__
  2. #define __TEXTEDITCONTROL__
  3.  
  4. #ifndef __TYPES__
  5. #include <Types.h>
  6. #endif
  7.  
  8. #ifndef __TEXTEDIT__
  9. #include <TextEdit.h>
  10. #endif
  11.  
  12. #ifndef __TEXTSERVICES__
  13. #include <TextServices.h>    
  14. #endif
  15.  
  16. #ifndef    __TSMTE__
  17. #include "TSMTE.h"
  18. #endif
  19.  
  20. #ifndef __WINDOWS__
  21. #include <Windows.h>
  22. #endif
  23.  
  24. typedef Boolean    (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, short *handled);
  25.     /*
  26.     **    ¶ Prototype for TextEditControl key filter function.
  27.     **
  28.     **    INPUT:    teHndl        TextEdit record that filter relates to.
  29.     **            event        Pointer to event record holding key event.
  30.     **    OUTPUT:    handled        Pointer to short to hold action.
  31.     **    RESULT:    Boolean        Return true if key should be filtered.
  32.     **
  33.     **    Each TextEdit control can have its own separate filter proc.  Just call
  34.     **    CTESetKeyFilter, and pass in the procPtr of your filter.  If the character
  35.     **    should be filtered, the filter should return true.  If you do return true,
  36.     **    then the value of “handled” is returned bt CTEKey.
  37.     **
  38.     **    Note that “handled” is initialized to 0, so you don’t have to set it unless
  39.     **    the desired  return value is other than 0.
  40.     **
  41.     **    __________
  42.     **
  43.     **    Also see:    CTEClick, CTEEvent, CTEKey, CTESetFastKeys, CTESetKeyFilter, IsCtlEvent. */ 
  44.  
  45. typedef Boolean    (*CTEFastKeysProcPtr)(TEHandle teHndl, EventRecord *event);
  46.     /*
  47.     **    ¶ Prototype for TextEditControl fast keys function.
  48.     **
  49.     **    INPUT:    teHndl        TextEdit record that fast keys proc relates to.
  50.     **            event        Pointer to event record holding key event.
  51.     **    RESULT:    Boolean        Return true if key should be seen by application.
  52.     **
  53.     **    On slower Macs, going back to the main event loop for every character can
  54.     **    adversely affect performance for TextEdit (and therefore the TextEdit control).
  55.     **    By using a fast-keys filter, you can prevent looping back to the main event loop.
  56.     **    The TextEdit control will loop itself, as long as there is a key in the
  57.     **    event queue.  Not all keys should be processed in fast-keys mode.  That is
  58.     **    the purpose of the filter.  If the filter determines that the key is okay to
  59.     **    be handled fast, it returns true.  If the key should be handled by the
  60.     **    application return false.
  61.     **
  62.     **    __________
  63.     **
  64.     **    Also see:    CTEClick, CTEEvent, CTEKey, CTESetFastKeys, CTESetKeyFilter, IsCtlEvent. */
  65.  
  66. typedef struct CTEDataRec {
  67.     short                maxTextLen;
  68.     Boolean                newUndo;
  69.     short                undoSelStart;
  70.     short                undoSelEnd;
  71.     Handle                undoText;
  72.     StScrpHandle        undoStyl;
  73.     short                mode;
  74.     Rect                brdrRect;
  75.     CTEKeyFilterProcPtr    keyFilter;
  76.     CTEFastKeysProcPtr    fastKeys;
  77.     TSMDocumentID        docID;
  78. } CTEDataRec;
  79. typedef CTEDataRec *CTEDataPtr, **CTEDataHndl;
  80.  
  81. pascal void        ASMNOCARET(Rect *caretRect);
  82. pascal Boolean    ASMTECLIKLOOP(void);
  83.     /*    Entry-points for the assembly glue. */
  84.  
  85. void            CTEActivate(Boolean active, TEHandle teHndl);
  86.     /*
  87.     **    ¶ Activate the indicated TextEdit record (and deactivate any other active one).
  88.     **
  89.     **    INPUT:    active        True to activate or false to deactivate.
  90.     **            teHndl        TextEdit record to activate (or deactivate).
  91.     **
  92.     **    Activate (or deactivate) this TextEdit record.  If another is currently
  93.     **    active, deactivate that one.  The view control for this TextEdit record is
  94.     **    also flagged to indicate which was the last active one for this window.
  95.     **    If the previous active TextEdit record was in the same window, then flag
  96.     **    the old one off for this window.  The whole point for this per-window
  97.     **    flagging is so that activate events can reactivate the correct TextEdit
  98.     **    control per window.
  99.     **
  100.     **    __________
  101.     **
  102.     **    Also see:    CTEFindActive, CTEWindActivate. */
  103.  
  104. Boolean            CTEClick(WindowPtr window, EventRecord *event, short *action);
  105.     /*
  106.     **    ¶ Handles a mouseDown in the content of a window.
  107.     **
  108.     **    INPUT:    window        Window click was made in.
  109.     **            event        Pointer to event record holding mouseDown event.
  110.     **    OUTPUT:    action        Action taken by the TextEdit control.
  111.     **                        Pass in nil if you don’t care.
  112.     **    RESULT:    Boolean        True if control used the event.
  113.     **
  114.     **    This is called when a mouseDown occurs in the content of a window.  It
  115.     **    returns true if the mouseDown caused a TextEdit action to occur.  Events
  116.     **    that are handled include if the user clicks on a scrollbar that is
  117.     **    associated with a TextEdit control.
  118.     **
  119.     **    if CTEClick returns false, action is 0
  120.     **    if CTEClick returns true,  action is:
  121.     **        -1 if control was activated by clicking on the TextEdit control or related scrollbar.
  122.     **         0 if control that was clicked on was already active.
  123.     **
  124.     **    __________
  125.     **
  126.     **    Also see:    CTEEvent, CTEKey. */
  127.  
  128. void            CTEClikLoop(void);
  129.     /*
  130.     **    ¶ Utility function for TextEdit control.
  131.     **
  132.     **    This is the custom clikLoop, which is called from the assembly glue code.
  133.     **    This handles updating the scrollbars as the user is drag-selecting in
  134.     **    the TextEdit control. */
  135.  
  136. ControlHandle    CTEClipboard(short menuID);
  137.     /*
  138.     **    ¶ Handles cut-copy-paste-clear for the currently active TextEdit control.
  139.     **
  140.     **    INPUT:    menuID            2 (cut), 3 (copy), 4 (paste), 5 (clear).
  141.     **    RESULT:    ControlHandle    Control that took the menu event.
  142.     **
  143.     **    Do the cut-copy-paste-clear operations for the currently active
  144.     **    TextEdit control.  Caller assumes appropriateness of the call.  Typically,
  145.     **    this routine won’t be called at an inappropriate time, since the menu
  146.     **    item should be enabled or disabled correctly.
  147.     **
  148.     **    Use CTEEditMenu to set the menu items undo-cut-copy-paste-clear correctly
  149.     **    for the active TextEdit control.  Since undo isn’t currently supported,
  150.     **    all that CTEEditMenu does for the undo case is to deactivate it right now.
  151.     **    If a TextEdit control content changes due to this operation, the control
  152.     **    handle is returned.
  153.     **
  154.     **    __________
  155.     **
  156.     **    Also see:    CTEConvertClipboard, CTEEditMenu. */
  157.  
  158. void            CTEConvertClipboard(Boolean convertClipboard, Boolean becomingActive);
  159.     /*
  160.     **    ¶ This is an empty function, used for backward-compatibility.
  161.     **
  162.     **    This used to be called to convert the clipboard.  This task is now handled
  163.     **    elsewhere, automatically.  Calls to this function are obsolete, and can be
  164.     **    removed.
  165.     **
  166.     **    __________
  167.     **
  168.     **    Also see:    CTEClipboard, CTEEditMenu. */
  169.  
  170. ControlHandle    CTECtlHit(void);
  171.     /*
  172.     **    ¶ Returns the control that was hit (if any) by FindControl.
  173.     **
  174.     **    RESULT:    ControlHandle    Control that was hit.
  175.     **
  176.     **    The TextEdit control that was hit by calling FindControl is saved in a
  177.     **    global variable, since the CDEF has no way of returning what kind it was.
  178.     **    To determine that it was a TextEdit control that was hit, first call this
  179.     **    function.  The first call returns the old value in the global variable,
  180.     **    plus it resets the global to nil.  Then call FindControl, and then
  181.     **    call this function again.  If it returns nil, then a TextEdit control
  182.     **    wasn’t hit.  If it returns non-nil, then it was a TextEdit control that
  183.     **    was hit, and specifically the one returned. */
  184.  
  185. void            CTEDispose(TEHandle teHndl);
  186.     /*
  187.     **    ¶ Disposes the TERecord, TextEdit control, and any related scrollbars.
  188.     **
  189.     **    INPUT:    teHndl        TextEdit handle (of the TextEdit control) to dispose.
  190.     **
  191.     **    Disposes of the TERecord, TextEdit control, and any related scrollbars.
  192.     **
  193.     **    __________
  194.     **
  195.     **    Also see:    CTEDisposeView. */
  196.  
  197. TEHandle        CTEDisposeView(ControlHandle viewCtl);
  198.     /*
  199.     **    ¶ Dispose the view control and related scrollbars, but not the TERecord.
  200.     **
  201.     **    INPUT:    viewCtl        Control to dispose.
  202.     **    RESULT:    TEHandle    Orphaned TextEdit record.
  203.     **
  204.     **    Dispose of the view control and related scrollbars.  This function also
  205.     **    returns the handle to the TextEdit record, since it was just orphaned.
  206.     **    Use this function if you want to get rid of a TextEdit control, but you
  207.     **    want to keep the TextEdit record.
  208.     **
  209.     **    __________
  210.     **
  211.     **    Also see:    CTEDispose. */
  212.  
  213. short            CTEDocHeight(TEHandle teHndl);
  214.     /*
  215.     **    ¶ Returns the full document height.
  216.     **
  217.     **    INPUT:    teHndl        TextEdit record to get height for.
  218.     **    RESULT:    short        Height of text in TextEdit record.
  219.     **
  220.     **    Returns the full TextEdit record text height.
  221.     **
  222.     **    __________
  223.     **
  224.     **    Also see:    CTEGetLineHeight, CTEGetLineNum. */
  225.  
  226. Boolean            CTEEditMenu(Boolean *activeItem, short editMenu, short undoID, short cutID);
  227.     /*
  228.     **    ¶ Handle the enabling and disabling of the Edit menu, based on the active TextEdit control.
  229.     **
  230.     **    INPUT:    editMenu    ID of Edit menu to adjust.
  231.     **            undoID        ID of Edit menu item for undo item.
  232.     **            cutID        ID of Edit menu item for cut item.
  233.     **    OUTPUT:    activeItem    Pointer to Boolean buffer.  True is returned if there is an active item.
  234.     **                        Pass in nil if you don’t care.
  235.     **    RESULT:    Boolean        True is returned if there is an active TextEdit record.
  236.     **
  237.     **    Enable or disable edit menu items based on the active TextEdit control.
  238.     **    You pass the menu ID of the undo item in undoID, and the menu ID of the
  239.     **    cut item in cutID.  If undoID or cutID is non-zero, then some action is
  240.     **    performed.  If you pass a non-zero value for cutID, then the other menu
  241.     **    items cut-copy-paste-clear are updated to reflect the status of the
  242.     **    active TextEdit control.
  243.     **
  244.     **    __________
  245.     **
  246.     **    Also see:    CTEClipboard, CTEConvertClipboard. */
  247.  
  248. Boolean            CTEEvent(WindowPtr window, EventRecord *event, short *action);
  249.     /*
  250.     **    ¶ Handle the event, either mouseDown or key event.
  251.     **
  252.     **    INPUT:    window        Window the event is for.
  253.     **            event        Pointer to the event record.
  254.     **    OUTPUT:    short        Pointer to a short buffer to hold the returned action.
  255.     **                        Pass in nil if you don’t care.
  256.     **    RESULT:    Boolean        True is returned if event is handled by a TextEdit control.
  257.     **
  258.     **    Handle the event if it applies to the active TextEdit control.  If some
  259.     **    action occured due to the event, return true.
  260.     **
  261.     **    if event not handled, false is returned and action is 0
  262.     **    if event handled, true is returned and action is:
  263.     **         -1: an inactive control was clicked on and it was made active.
  264.     **         0: an active control was clicked on and tracked.
  265.     **         1: the control took the keypress, but no change occured to the TERecord.
  266.     **         2: the control took the keypress and the TERecord changed.
  267.     **
  268.     **    __________
  269.     **
  270.     **    Also see:    CTEClick, CTEKey. */
  271.  
  272. TEHandle        CTEFindActive(WindowPtr window);
  273.     /*
  274.     **    ¶ See if there is an active TextEdit control for this window.
  275.     **
  276.     **    INPUT:    window        Window to check for an active TextEdit control (or nil for all).
  277.     **    RESULT:    TEHandle    The TEHandle of the active TextEdit control (or nil for none).
  278.     **
  279.     **    Returns the active TextEdit control, if any.  If nil is passed in, then
  280.     **    the return value represents whatever TextEdit control is active, independent
  281.     **    of what window it is in.  If a window is passed in, then it returns a
  282.     **    TextEdit control only if the active control is in the specified window.
  283.     **    If the active TextEdit control is in some other window, then nil is returned.
  284.     **
  285.     **    __________
  286.     **
  287.     **    Also see:    CTEActivate, CTEWindActivate. */
  288.  
  289.  
  290. ControlHandle    CTEFindCtl(WindowPtr window, EventRecord *event, TEHandle *teHndl,
  291.                            ControlHandle *ctlHit);
  292.     /*
  293.     **    ¶ See if a TextEdit control was clicked on directly.
  294.     **
  295.     **    INPUT:    window            Window to check for a clicked-on TextEdit control.
  296.     **            event            Pointer to the event record holding the mouseDown to check.
  297.     **    OUTPUT:    TEHandle        The TEHandle of the clicked-on TextEdit control (or nil for none).
  298.     **                            Pass in nil if you don’t care.
  299.     **            CtlHit            The control clicked-on (or nil for none).
  300.     **                            Pass in nil if you don’t care.
  301.     **    RESULT:    ControlHandle    The TextEdit control clicked-on (or nil for none).
  302.     **
  303.     **    This determines if a TextEdit control was clicked on directly.  The control found
  304.     **    and returned is the TextEdit control.  The control hit may be the same, or it may be
  305.     **    a related scrollbar. */
  306.  
  307. TEHandle        CTEFromScroll(ControlHandle scrollCtl, ControlHandle *retCtl);
  308.     /*
  309.     **    ¶ Find the TextEdit record that is related to the indicated scrollbar.
  310.     **
  311.     **    INPUT:    scrollCtl        Window to check for a clicked-on TextEdit control.
  312.     **    OUTPUT:    retCtl            The TextEdit control related to the scrollBar (or nil for none).
  313.     **                            Pass in nil if you don’t care.
  314.     **    RESULT:    TEHandle        The TERecord clicked-on (or nil for none).
  315.     **
  316.     **    Find the TextEdit record that is related to the indicated scrollbar. */
  317.  
  318. Rect            CTEHide(TEHandle teHndl);
  319.     /*
  320.     **    ¶ Hide the designated TextEdit control and related scrollbars.
  321.     **
  322.     **    INPUT:    teHndl        TextEdit control to hide.
  323.     **    Rect:    Rect        Bounding box of area affected by hide.
  324.     **
  325.     **    Hide the designated TextEdit control and related scrollbars. */
  326.  
  327. void            CTEIdle(void);
  328.     /*
  329.     **    ¶ Blink the caret in the active TextEdit control.
  330.     **
  331.     **    Blink the caret in the active TextEdit control.  The active TextEdit
  332.     **    control may be read-only, in which case the caret does not blink. */
  333.  
  334. short            CTEKey(WindowPtr window, EventRecord *event);
  335.     /*
  336.     **    ¶ Does keypress apply to TextEdit control?  If so, handle it and return non-zero.
  337.     **
  338.     **    INPUT:    window        Window to check for active TextEdit control for key.
  339.     **            event        Pointer to event record holding keypress.
  340.     **    RESULT:    short        Action taken by TextEdit control due to keypress.
  341.     **
  342.     **    See if the keypress event applies to the TextEdit control, and if it does,
  343.     **    handle it and return non-zero.
  344.     **
  345.     **    if CTEKey returns 0, TextEdit control didn’t handle the event.
  346.     **    if CTEKey returns 1, TextEdit control did handle the event, but the TERecord didn’t change.
  347.     **    if CTEKey returns 2, TextEdit control did handle the event, and the TERecord changed. */
  348.  
  349. void            CTEMove(TEHandle teHndl, short newH, short newV);
  350.     /*
  351.     **    ¶ Move the designated TextEdit control and related scrollbars.
  352.     **
  353.     **    INPUT:    teHndl    TextEdit control to move.
  354.     **            newH    New horizontal location for TextEdit control.
  355.     **            newV    New vertical location for TextEdit control.
  356.     **
  357.     **    This function is used to move a TextEdit control.  Pass it the TextEdit
  358.     **    record to move, plus the new position.  It will move the TextEdit control,
  359.     **    along with any scrollbars the control may have.  All areas that need
  360.     **    updating are cleared and invalidated. */
  361.  
  362. OSErr            CTENew(short viewID, Boolean vis, WindowPtr window, TEHandle *teHndl, Rect *cRect,
  363.                        Rect *dRect, Rect *vRect, Rect *bRect, short maxTextLen, short mode);
  364.  
  365.     /*
  366.     **    ¶ Create a new TextEdit control.
  367.     **
  368.     **    INPUT:    viewID        Resource number of the stub CDEF.
  369.     **            vis            Create control initially visible.
  370.     **            window        Create control into this window.
  371.     **            cRect        Pointer to rect for TextEdit control view rect.
  372.     **            dRect        Pointer to rect for TextEdit destRect.
  373.     **            vRect        Pointer to rect for TextEdit viewRect.
  374.     **            bRect        Pointer to rect for TextEdit control border rect.
  375.     **            maxTextLen    Maximum length allowed for TextEdit record.
  376.     **            mode        Choose various TextEdit control options.
  377.     **    OUTPUT:    teHndl        Pointer to TEHandle to be created.
  378.     **                        Pass in nil if you don’t care.
  379.     **    RETURN:    OSErr        Reason for control creation failure.
  380.     **
  381.     **    To create a TextEdit control, you only need a single call.  For example:
  382.     **
  383.     **        mode = cteVScrollLessGrow;        TERecord read-write, with vertical scroll
  384.     **                                        that leaves space for grow box.
  385.     **
  386.     **        CTENew(rViewCtl,        Resource ID of view control for TextEdit control.
  387.     **               window,            Window to hold TERecord.
  388.     **               true,            Initially visible.
  389.     **               &teHndl,            Return handle for TERecord.
  390.     **               &ctlRect,        Rect for TextEdit view control.
  391.     **               &destRect,        destRect for TERecord.
  392.     **               &viewRect,        viewRect for TERecord.
  393.     **               &brdrRect,        Used to frame a border.
  394.     **               32000,            Max size for TERecord text.
  395.     **               mode);
  396.     **
  397.     **    The various choices for the TextEdit control are defined as follows:
  398.     **
  399.     **    #define cteReadOnly            0x0001
  400.     **    #define cteHScroll            0x0002
  401.     **    #define cteHScrollLessGrow    0x0006
  402.     **    #define cteVScroll            0x0008
  403.     **    #define cteVScrollLessGrow    0x0018
  404.     **    #define cteActive            0x0020
  405.     **    #define cteNoBorder            0x0040
  406.     **    #define cteShowActive        0x0080
  407.     **    #define cteTabSelectAll        0x0100
  408.     **    #define cteTwoStep            0x0200
  409.     **    #define cteScrollFullLines    0x0400
  410.     **    #define cteStyledTE            0x0800
  411.     **    #define cteCenterJustify    0x1000
  412.     **    #define cteRightJustify        0x2000
  413.     **    #define cteNoFastKeys        0x4000
  414.     **
  415.     **    cteReadOnly:        Don’t allow editing.  When selected, don’t blink a caret.
  416.     **                        Allow text selection and copy-to-clipboard.
  417.     **    cteHScroll:            Create and manage a horizontal scrollbar for the TextEdit control.
  418.     **    cteHScrollLessGrow:    Create and manage a horizontal scrollbar for the TextEdit control,
  419.     **                        but leave space for a growIcon on the right end of the scrollbar.
  420.     **    cteVScroll:            Create and manage a vertical scrollbar for the TextEdit control.
  421.     **    cteVScrollLessGrow:    Create and manage a vertical scrollbar for the TextEdit control,
  422.     **                        but leave space for a growIcon on the bottom end of the scrollbar.
  423.     **    cteActive:            Make this the initially active control for the window.
  424.     **    cteNoBorder:        By default, you get a border around the TextEdit control.  To turn this
  425.     **                        off, set this bit.
  426.     **    cteShowActive:        When the control is active, show that it is by drawing a selection
  427.     **                        border around the control.  This is the new 7.0 human-interface
  428.     **                        method of showing which control is active.  (This can be an important
  429.     **                        indicator because if you have readOnly TextEdit controls, they don’t
  430.     **                        have a blinking caret.  If they also don’t have any text selected,
  431.     **                        there will be no indication that it is the active control.
  432.     **    cteTabSelectAll:    When using IsCtlEvent (discussed under "! using CtlHandler.c"),
  433.     **                        tab changes the active TextEdit (or List) control.  When a TextEdit
  434.     **                        control is made active, sometimes it is desirable to initially select
  435.     **                        all of the text for the user.  Setting this bit accomplishes this.
  436.     **    cteTwoStep:            When using IsCtlEvent, you may want the initial click on a TextEdit
  437.     **                        control to just select the control, or you may wish the click to start
  438.     **                        tracking in addition to selecting the control.  The tracking is
  439.     **                        considered the second step, so by setting this bit, you will get
  440.     **                        tracking of the control on the initial click.
  441.     **    cteScrollFullLines:    This does as it sounds, but only if the TextEdit control isn’t styled.
  442.     **    cteStyledTE:        If you don’t need styles for this TextEdit control, leave this bit off.
  443.     **    cteCenterJustify:    As it sounds.
  444.     **    cteRightJustify:    As it sounds.
  445.     **    cteNoFastKeys:        The fast-keys feature allows the TextEdit control to check the OSEvent
  446.     **                        queue to see if there is another key event.  If there is, it will
  447.     **                        handle it before returning control to the application.  This local
  448.     **                        event processing allows a great speed increase in TextEdit performance,
  449.     **                        especially on slower Macs.  Some applications will want to inhibit
  450.     **                        this behavior.  Set this bit if you do.
  451.     **
  452.     **    Simply initialize ctlRect, destRect, viewRect, and brdrRect appropriately, and
  453.     **    then call CTENew (which stands for Control TENew).  If teHndl is returned
  454.     **    nil, then CTENew failed.  Otherwise, you now have a TextEdit control in the
  455.     **    window.  If it fails, it also returns an error stating why it failed
  456.     **    (memFullErr or resNotFound).
  457.     **
  458.     **    NOTE:    There is a TextEdit bug (no way!!) such that you may need to set the
  459.     **            viewRect right edge 2 bigger than the right edge of destRect.  If you
  460.     **            do not do this, then there will be some clipping on the right edge in
  461.     **            some cases.  Of course, you may want this.  You may want horizontal
  462.     **            scrolling, and therefore you would want the destRect substantially
  463.     **            larger than the viewRect.  If you don’t want horizontal scrolling,
  464.     **            then you probably don’t want any clipping horizontally, and therefore
  465.     **            you will need to set destRect.right 2 less than viewRect.right.
  466.     **
  467.     **
  468.     **    If the CTENew call succeeds, you then have a TextEdit control in your
  469.     **    window.  It will be automatically disposed of when you close the window.
  470.     **    If you don’t waht this to happen, then you can detach it from the
  471.     **    view control which owns it.  To do this, you would to the following:
  472.     **
  473.     **        viewCtl = CTEViewFromTE(theTextEditHndl);
  474.     **        if (viewCtl) SetCRefCon(viewCtl, nil);
  475.     **
  476.     **    The view control keeps a reference to the TERecord in the refCon.
  477.     **    If the refCon is cleared, then the view control does nothing.  So, all that
  478.     **    is needed to detach a TERecord from a view control is to set the
  479.     **    view control’s refCon nil.  Now if you close the window, you will still
  480.     **    have the TERecord.
  481.     **
  482.     **
  483.     **    To remove a TextEdit control completely from a window, you make one call:
  484.     **
  485.     **        CTEDispose(theTextEditHndl);
  486.     **
  487.     **    This disposes of the TERecord, the view control, and any scrollbar
  488.     **    controls that were created when the TextEdit control was created with
  489.     **    the call CTENew.
  490.     **
  491.     **
  492.     **    Events for TERecord are handled nearly automatically.  You can
  493.     **    make one of 3 calls:
  494.     **
  495.     **        CTEClick(window, eventPtr, &action);
  496.     **        CTEEvent(window, eventPtr, &action);
  497.     **        CTEKey(window, eventPtr);
  498.     **
  499.     **    In each case, if the event was handled, non-zero is returned.  CTEEvent simply
  500.     **    calls either CTEClick or CTEKey, whichever is appropriate.
  501.     **
  502.     **    Another call you will want to use is CTEEditMenu.  This is used to set the
  503.     **    state of cut/copy/paste/clear for TextEdit controls.  It checks the active
  504.     **    control to see if text is selected, if the control is read-only, etc.
  505.     **    Based on this information, it sets cut/copy/paste/clear either active
  506.     **    or inactive.  If any menu items are set active, it returns true.
  507.     **
  508.     **
  509.     **    One more high-level call is CTEUndo.  In response to an undo menu item
  510.     **    being selected by the user, just call CTEUndo, and the edits the user
  511.     **    has made will be undone.  (This includes undoing an undo.)
  512.     **
  513.     **
  514.     **    The last high-level call for managing the edit menu is CTEClipboard.  Call it
  515.     **    when you want to do a cut/copy/paste/clear for the active TextEdit control.
  516.     **    The value to pass is as follows:
  517.     **
  518.     **        2: cut
  519.     **        3: copy
  520.     **        4: paste
  521.     **        5: clear
  522.     **
  523.     **    These are the same values you would pass to a DA for these actions. */
  524.  
  525. void            CTENewUndo(ControlHandle viewCtl, Boolean alwaysNewUndo);
  526.     /*
  527.     **    ¶ Register a new undo for the next TextEdit control editing operation.
  528.     **
  529.     **    INPUT:    viewCtl            Control to set a new undo for.
  530.     **            alwaysNewUndo    True if undo should be forced.  (Not the case for normal typing.)
  531.     **
  532.     **    Save the data (if appropriate) so that user can undo. */
  533.  
  534. ControlHandle    CTENext(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
  535.     /*
  536.     **    ¶ Interate to the next TextEdit control.
  537.     **
  538.     **    INPUT:    window            Window whose control list is iterated.
  539.     **            ctl                Last control.  Find next.  (Use nil to start at beginning of list.)
  540.     **            dir                1, walk control list forward.  -1, walk control list backward.
  541.     **            justActive        True is just active (visible, hilite != -1).
  542.     **    OUTPUT:    teHndl            Pointer to next TEHandle in list, based on criteria.
  543.     **                            Pass in nil if you don’t care.
  544.     **    RETURN:    ControlHandle    Next control in list, based on criteria.
  545.     **
  546.     **    Get the next TextEdit control in the window.  You pass it a control handle
  547.     **    for the view control, or nil to start at the beginning of the list.
  548.     **    It returns both a TextEdit handle and the view control handle for that
  549.     **    TextEdit record.  If none is found, nil is returned.  This allows you to
  550.     **    repeatedly call this function and walk through all the TextEdit controls
  551.     **    in a window. */
  552.  
  553. short            CTENumTextLines(TEHandle teHndl);
  554.     /*
  555.     **    ¶ Get correct number of line in the TextEdit handle.
  556.     **
  557.     **    INPUT:    teHndl        TextEdit handle to count lines on.
  558.     **    RETURN:    short        Number of lines in TextEdit handle.
  559.     **
  560.     **    Return the number of lines of text.  This is because there is a bug in
  561.     **    TextEdit where the number of lines returned is incorrect if the text
  562.     **    ends with a c/r.  This function adjusts for this bug. */
  563.  
  564. OSErr            CTEPrint(TEHandle teHndl, short *offset, Rect *rct);
  565.     /*
  566.     **    ¶ Get correct number of line in the TextEdit handle.
  567.     **
  568.     **    INPUT:    teHndl        TextEdit handle to print.
  569.     **    IN/OUT    offset        Pointer to short holding offset to continue printing from.
  570.     **            Rect        Pointer to rect that text is wrapped in, and wrapped text
  571.     **                        boundary is returned in.
  572.     **    RETURN:    OSErr        Some kind of error prevented completion (likely memFullErr).
  573.     **
  574.     **    Use this function to print the contents of a TextEdit record.  Pass it a
  575.     **    TextEdit handle, a pointer to a text offset, and a pointer to a rect to
  576.     **    print the text in.  The offset should be initialized to what character
  577.     **    in the TextEdit record you wish to start printing at (most likely 0).
  578.     **    The print function prints as much text as will fit in the rect, and
  579.     **    then updates the offset to tell you what is the first character that didn’t
  580.     **    print.  You can then call the print function again with another rect with
  581.     **    this new offset, and it will print the text starting at the new offset.
  582.     **    This method is very useful when a single TextEdit record is longer than a
  583.     **    single page, and you wish the text to break at the end of the page.
  584.     **    The bottom of rect is also updated, along with the offset.  The bottom edge
  585.     **    of the rect is changed to reflect the actual bottom of the text printed.
  586.     **    This is useful because the rect passed in didn’t necessarily hold an
  587.     **    integer number of lines of text.  The bottom of the rect is adjusted so
  588.     **    it exactly holds complete lines of text.
  589.     **    It is also possible that the rect could hold substantially more lines of
  590.     **    text than there are remaining.  Again, in this situation, the bottom of
  591.     **    rect is adjusted so that the rect tightly bounds the text printed.
  592.     **    The remaining piece of information passed back is an indicator that the
  593.     **    text through the end of the TextEdit record was printed.  When the end
  594.     **    of the text is reached, the offset for the next text to be printed is
  595.     **    returned as -1.  This indicates that processing of the TextEdit record
  596.     **    is complete. */
  597.  
  598. Boolean            CTEReadOnly(TEHandle teHndl);
  599.     /*
  600.     **    ¶ Return if the TextEdit control is read-write (true) or read-only (false).
  601.     **
  602.     **    INPUT:    teHndl        TextEdit handle in question.
  603.     **    RETURN:    Boolean        read-write (true) or read-only (false).
  604.     **
  605.     **    Return if the TextEdit control is read-write (true) or read-only (false). */
  606.  
  607. ControlHandle    CTEScrollFromTE(TEHandle teHndl, Boolean vertScroll);
  608.     /*
  609.     **    ¶ Return control handle of scrollbar related to the TextEdit record.
  610.     **
  611.     **    INPUT:    teHndl        TextEdit handle in question.
  612.     **    RETURN:    Boolean        read-write (true) or read-only (false).
  613.     **
  614.     **    Return the control handle for the TextEdit control’s scrollbar, either
  615.     **    vertical or horizontal.  If the scrollbar doesn’t, nil is returned. */
  616.  
  617. ControlHandle    CTEScrollFromView(ControlHandle viewCtl, Boolean vertScroll);
  618.     /*
  619.     **    ¶ Return control handle of scrollbar related to the TextEdit control.
  620.     **
  621.     **    INPUT:    viewCtl        TextEdit control in question.
  622.     **    RETURN:    Boolean        read-write (true) or read-only (false).
  623.     **
  624.     **    Return the control handle for the scrollbar related to the view control,
  625.     **    either horizontal or vertical.  If the scrollbar doesn’t exist, return nil. */
  626.  
  627. void            CTESetKeyFilter(TEHandle teHndl, CTEKeyFilterProcPtr proc);
  628.     /*
  629.     **    ¶ Set TextEdit handle to be filtered.
  630.     **
  631.     **    INPUT:    teHndl        TextEdit handle to be filtered.
  632.     **            proc        Filter procedure for TextEdit handle.
  633.     **
  634.     **    A TextEdit control can have an optional key filter, which is called whenever
  635.     **    CTEKey is called.  If you pass in nil, then the filtering is turned off.
  636.     **    This allows individual TextEdit controls to handle their own filtering.
  637.     **    The filter procedure is of the form:
  638.     **        Boolean (*CTEKeyFilterProcPtr)(TEHandle teHndl, EventRecord *event, Boolean *handled);
  639.     **    If true is returned, then CTEKey is aborted, and the value in "handled" is
  640.     **    returned.  By having a separate abort value and return value, you can determine
  641.     **    if processing of the event should be continued or not, independent of whether
  642.     **    or not you aborted CTEKey. */
  643.  
  644. void            CTESetFastKeys(TEHandle teHndl, CTEFastKeysProcPtr proc);
  645.     /*
  646.     **    ¶ Set TextEdit handle to accept keys "fast", i.e., in a local loop.
  647.     **
  648.     **    INPUT:    teHndl        TextEdit handle to be filtered.
  649.     **            proc        Fast-keys procedure.
  650.     **
  651.     **    Set your own fast-keys procedure.  The fast-keys procedure returns whether or not
  652.     **    the particular keypress can be handled without returning to the application.
  653.     **    If the key can be handled as a fast key, then the proc should return true. */
  654.  
  655. void            CTESetSelect(short start, short end, TEHandle teHndl);
  656.     /*
  657.     **    ¶ Set a range of text.  Use this instead of TESetSelect.
  658.     **
  659.     **    INPUT:    start        Offset of first char to be included in the selection range.
  660.     **            stop        Offset past last character to be included in the selection range.
  661.     **            teHndl        TextEdit handle to receive selection range.
  662.     **
  663.     **    Select a range of text.  TESetSelect can’t be used alone because it doesn’t
  664.     **    update the scrollbars.  This function calls TESetSelect, and then fixes up
  665.     **    the scrollbars. */
  666.  
  667. void            CTEShow(TEHandle teHndl);
  668.     /*
  669.     **    ¶ Unhide a hidden TextEdit control.
  670.     **
  671.     **    INPUT:    teHndl        TextEdit handle to unhide.
  672.     **
  673.     **    Show the designated TextEdit control and related scrollbars. */
  674.  
  675. void            CTESize(TEHandle teHndl, short newH, short newV, Boolean newDest);
  676.     /*
  677.     **    ¶ Change the size of a TextEdit control and related scrollbars.
  678.     **
  679.     **    INPUT:    teHndl        TextEdit handle to resize.
  680.     **            newH        New horizontal size.
  681.     **            newV        New vertical size.
  682.     **            newDest        Resize the destRect, along with other changes.
  683.     **
  684.     **    This function is used to resize a TextEdit control.  Pass it the TextEdit
  685.     **    record to resize, plus the new horizontal and vertical size.  It will
  686.     **    resize the TextEdit control, realign the text, if necessary, plus it will
  687.     **    resize and adjust any scrollbars the TextEdit control may have.  All areas
  688.     **    that need updating are cleared and invalidated. */
  689.  
  690. Handle            CTESwapText(TEHandle teHndl, Handle newText, StScrpHandle styl, Boolean update);
  691.     /*
  692.     **    ¶ Change the size of a TextEdit control and related scrollbars.
  693.     **
  694.     **    INPUT:    teHndl        TextEdit handle to accept text.
  695.     **            newText        Handle of new text for TextEdit control.
  696.     **            styl        Optional style record (nil if none).
  697.     **            update        True if new text should be drawn after being accepted.
  698.     **
  699.     **    Swap the TextEdit text handle with the text handle passed in.  If a non-nil styl
  700.     **    value is passed in, apply the style scrap to the new text.  A typical usage
  701.     **    might look like:
  702.     **
  703.     **        DisposeHandle(CTESwapText(teHndl, textHndl, stylHndl, false));
  704.     **
  705.     **    CTESwapText returns the old handle, which is then disposed of, since it is
  706.     **    typically no longer needed. */
  707.  
  708.  
  709. WindowPtr        CTETargetInfo(TEHandle *teHndl, Rect *teView);
  710.     /*
  711.     **    ¶ Get information about the target TextEdit control.
  712.     **
  713.     **    OUTPUT:    teHndl        Active TextEdit handle (nil if none).
  714.     **                        Pass in nil if you don’t care.
  715.     **            teView        Bounding viewRct of activeTextEdit handle.
  716.     **                        Pass in nil if you don’t care.
  717.     **    RESULT:    WindowPtr    Window containing active TextEdit control.
  718.     **
  719.     **    Return information for the currently active TextEdit control.  The currently
  720.     **    active TextEdit control is stored in gActiveTEHndl, and can be accessed
  721.     **    directly.  If gActiveTEHndl is nil, then there is no currently active one.
  722.     **    The information that we return is the viewRect and window of the active
  723.     **    TextEdit control.  This is information that could be gotten directly, but
  724.     **    this call makes it a little more convenient. */
  725.  
  726. ControlHandle    CTEUndo(void);
  727.     /*
  728.     **    ¶ Perform an undo function for the TextEdit control.
  729.     **
  730.     **    Perform an undo function for the TextEdit control.
  731.     **    If a TextEdit control content changes due to this operation, the control
  732.     **    handle is returned. */
  733.  
  734. void            CTEUpdate(TEHandle teHndl, ControlHandle ctl, Boolean justShowActive);
  735.     /*
  736.     **    ¶ Draw the TextEdit control and frame.
  737.     **
  738.     **    INPUT:    teHndl                TextEdit handle to draw.
  739.     **            ctl                    TextEdit control to draw.
  740.     **            justShowActive        Just draw the active indicator, if any.
  741.     **
  742.     **    Draw the TextEdit control and frame, or possibly just the frame. */
  743.  
  744. ControlHandle    CTEViewFromTE(TEHandle teHndl);
  745.     /*
  746.     **    ¶ Get the control handle, give the TextEdit record.
  747.     **
  748.     **    INPUT:    teHndl                TextEdit handle to convert to control.
  749.     **
  750.     **    Return the control handle for the view control that owns the TextEdit
  751.     **    record.  Use this to find the view to do customizations such as changing
  752.     **    the update procedure for this TextEdit control. */
  753.  
  754. TEHandle        CTEWindActivate(WindowPtr window, Boolean displayIt);
  755.     /*
  756.     **    ¶ Activate the TextEdit control for the activating window.
  757.     **
  758.     **    INPUT:    window            Window that was activated.
  759.     **            displayIt        Display the activation differences.
  760.     **    RETURN:    TEHandle        The activated TextEdit handle (or nil for none).
  761.     **
  762.     **    Call this when a window with TextEdit controls is being activated.  This
  763.     **    will make the TextEdit control that was last active in this window the
  764.     **    active TextEdit control again. */
  765.  
  766. void            CTEAdjustTEBottom(TEHandle teHndl);
  767.     /*
  768.     **    ¶ Adjust the bottom of the TextEdit record to remove extra white space.
  769.     **
  770.     **    INPUT:    teHndl            TextEdit record to adjust.
  771.     **
  772.     **    This function is called after an edit to make sure that there is no extra
  773.     **    white space at the bottom of the viewRect.  If there are blank lines at
  774.     **    the bottom of the viewRect, and there is text scrolled off the top of the
  775.     **    viewRect, then the TextEdit control is scrolled to fill this space, or as
  776.     **    much of it as possible. */
  777.  
  778. void            CTEAdjustScrollValues(TEHandle teHndl);
  779.     /*
  780.     **    ¶ Adjust the scrollbar values to the TextEdit length and scroll position.
  781.     **
  782.     **    INPUT:    teHndl        TextEdit record whose scrollbars are to be adjusted.
  783.     **
  784.     **    Bring the scrollbar values up to date with the current document position
  785.     **    and length. */
  786.  
  787. StScrpHandle    CTEGetFullStylScrap(TEHandle teHndl);
  788.     /*
  789.     **    ¶ Get the style scrap for the entire TextEdit control.
  790.     **
  791.     **    INPUT:    teHndl        TextEdit record to get scrap for.
  792.     **
  793.     **    This function gets the style scrap for the entire TextEdit control.  It doesn’t
  794.     **    matter what the current selection range is.  The TextEdit control is left unaffected. */
  795.  
  796. void            CTESetStylScrap(short begRng, short endRng, StScrpHandle styles, TEHandle teHndl);
  797.     /*
  798.     **    ¶ Apply the style scrap to the TextEdit record.
  799.     **
  800.     **    INPUT:    begRng        Beginning of range (inclusive) to apply style to.
  801.     **            endRng        End of range (exclusive) to apply style to.
  802.     **            styles        Scrap syyles to apply.
  803.     **            teHndl        TextEdit record to apply styles to.
  804.     **
  805.     **    This function applies the style scrap to the TextEdit record.  This function works better
  806.     **    than the toolbox function TESetStylScrap. */
  807.  
  808. short            CTEGetLineNum(TEHandle te, short offset);
  809.     /*
  810.     **    ¶ Return the line number associated with the offset passed in.
  811.     **
  812.     **    INPUT:    te            TextEdit handle to get the line number for.
  813.     **            offset        Offset to find the line number for.
  814.     **
  815.     **    This function returns the line number associated with the offset passed in. */
  816.  
  817. short            CTEGetLineHeight(TEHandle te, short lineNum, short *ascent);
  818.     /*
  819.     **    ¶ Return the line height of the requested line number.
  820.     **
  821.     **    INPUT:    te            TextEdit handle to get the line number for.
  822.     **            lineNum        Line number to get height for.
  823.     **    OUTPUT:    ascent        Ascent of line lineNum.
  824.     **                        Pass in nil if you don’t care.
  825.     **    RESULT:    short        Line height of line lineNum.
  826.     **
  827.     **    This function returns the line height of the requested line number. */
  828.  
  829. void            CTEGetPStr(ControlHandle ctl, StringPtr pstr);
  830.     /*
  831.     **    ¶ Return the TextEdit control text as a pascal string.
  832.     **
  833.     **    INPUT:    ctl            TextEdit control to get pascal string for.
  834.     **    OUTPUT:    pstr        Pascal string pointer to receive text.
  835.     **
  836.     **    This function returns the TextEdit control text as a pascal string.  The maximum text
  837.     **    returned is 255 chars. */
  838.  
  839. void            CTEPutPStr(ControlHandle ctl, StringPtr pstr);
  840.     /*
  841.     **    ¶ Set the TextEdit control text to a pascal string.
  842.     **
  843.     **    INPUT:    ctl            TextEdit control to get pascal string for.
  844.     **            pstr        Pascal string pointer that holds new TextEdit control text.
  845.     **
  846.     **    This function sets the TextEdit control text to the pascal string. */
  847.  
  848. void            CTESetPStr(ControlHandle ctl, StringPtr pstr);
  849.     /*
  850.     **    ¶ Set the TextEdit control text to a pascal string.
  851.     **
  852.     **    INPUT:    ctl            TextEdit control to get pascal string for.
  853.     **            pstr        Pascal string pointer that holds new TextEdit control text.
  854.     **
  855.     **    This function sets the TextEdit control text to the pascal string. */
  856.  
  857. Boolean            CTEUseTSMTE(void);
  858.     /*
  859.     **    ¶ Set the TextEdit control to use TSMTE.
  860.     **
  861.     **    OUTPUT:    Boolean        Returns true if can use TSMTE.
  862.     **
  863.     **    Call this function if you want the TextEdit control to use TSMTE.  You still need to
  864.     **    register and unregister your application with the TextServices Manager.  That isn’t
  865.     **    handled for you.  AppWannabe’s Start.c file shows how this is done:
  866.     **
  867.     **    if(CTEUseTSMTE())
  868.     **        InitTSMAwareApplication();
  869.     **
  870.     **    ... do app things here ...
  871.     **
  872.     **    if(CTEUseTSMTE())
  873.     **        CloseTSMAwareApplication();
  874.     **
  875.     **    ExitToShell();
  876.     */
  877.  
  878. Boolean            TSMTEAvailable(void);
  879.     /*
  880.     **    ¶ Check if TextServices init TSMTE is available.
  881.     **
  882.     **    OUTPUT:    Boolean        Returns true if TSMTE is available.
  883.     **
  884.     **    This function says if the TextServices init TSMTE is available for inline-input for
  885.     **    TextEdit.  Note that you should do the following at startup:
  886.     **
  887.     **            if(TSMTEAvailable())
  888.     **            InitTSMAwareApplication();
  889.     **
  890.     **    And at application shutdown, you should do the following:
  891.     **
  892.     **            if(TSMTEAvailable())
  893.     **            CloseTSMAwareApplication();
  894.     */
  895.  
  896. Boolean            IsTECtl(ControlHandle ctl);
  897.     /*
  898.     **    ¶ Check if the control is a TextEdit control.
  899.     **
  900.     **    INPUT:    ctl            Handle of control to test to see if it is a TextEdit control.
  901.     **    RESULT:    Boolean        True if control is a TextEdit control.
  902.     **
  903.     **    Check to see if the control is a TextEdit control. */
  904.  
  905.  
  906.  
  907. typedef void            (*CTEActivateProcPtr)(Boolean active, TEHandle teHndl);
  908. typedef Boolean            (*CTEClickProcPtr)(WindowPtr window, EventRecord *event, short *action);
  909. typedef ControlHandle    (*CTECtlHitProcPtr)(void);
  910. typedef TEHandle        (*CTEFindActiveProcPtr)(WindowPtr window);
  911. typedef short            (*CTEKeyProcPtr)(WindowPtr window, EventRecord *event);
  912. typedef ControlHandle    (*CTENextProcPtr)(WindowPtr window, TEHandle *teHndl, ControlHandle ctl, short dir, Boolean justActive);
  913. typedef void            (*CTESetSelectProcPtr)(short start, short end, TEHandle teHndl);
  914. typedef ControlHandle    (*CTEViewFromTEProcPtr)(TEHandle teHndl);
  915. typedef TEHandle        (*CTEWindActivateProcPtr)(WindowPtr window, Boolean displayIt);
  916.  
  917. #define rTECtl                4000
  918.  
  919. #define cteReadOnly            0x0001
  920. #define cteHScroll            0x0002
  921. #define cteHScrollLessGrow    0x0006
  922. #define cteVScroll            0x0008
  923. #define cteVScrollLessGrow    0x0018
  924. #define cteActive            0x0020
  925. #define cteNoBorder            0x0040
  926. #define cteShowActive        0x0080
  927. #define cteTabSelectAll        0x0100
  928. #define cteTwoStep            0x0200
  929. #define cteScrollFullLines    0x0400
  930. #define cteStyledTE            0x0800
  931. #define cteCenterJustify    0x1000
  932. #define cteRightJustify        0x2000
  933. #define cteNoFastKeys        0x4000
  934. #define cteTSMTE            0x8000
  935.  
  936. #endif
  937.